package com.jk.admin.controller;

import com.jk.admin.entity.Advert;

import com.jk.admin.service.AdvService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
public class AdvController {
    @Autowired
    private AdvService advService;

    @RequestMapping("getListAdv")
    public List<Advert> getListAdv(Advert advert){

        return advService.getListAdv(advert);

    }


    @RequestMapping("AdvById")
    public Advert AdvById(Integer id){

        return advService.AdvById(id);
    }


    @RequestMapping("updAdv")
    public void updPro(Advert advert, HttpServletRequest request){
        String img = (String) request.getSession().getAttribute("img");
        advert.setAdvert_pic(img);
        System.out.println(img+"-----s----ss------s-----");
        advService.updAdv(advert);
    }

    @RequestMapping("delAdv")
    public void delAdv(Integer id) {
        advService.delAdv(id);
    }


    @RequestMapping("addAdv")
    public void addAdv(Advert advert,HttpServletRequest request){
        String img = (String) request.getSession().getAttribute("img");
        advert.setAdvert_pic(img);
        System.out.println(img+"-----s----ss------s-----");
        advService.addAdv(advert);
    }
}




